package com.neuedu.config;

import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;

import java.lang.reflect.Type;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/** 序列转换器
 * 实现了ObjectDeserializer接口的类，用于反序列化LocalDateTime对象
 * 该类定义了如何将JSON字符串转换回LocalDateTime对象
 */
public class LocalDateTimeDeserialized implements ObjectDeserializer {
    @Override
    public LocalDateTime deserialze(DefaultJSONParser defaultJSONParser, Type type, Object o) {
        String content = defaultJSONParser.getLexer().getReader().readString();
        return LocalDateTime.parse(content, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }
}
